import { createSSRApp } from "vue";
import App from "./App.vue";
import createRouter from "./router";
import { createMemoryHistory } from "vue-router";
import { createPinia } from "pinia";

// 通过函数返回app实例，保证每个请求都是新的实例，避免夸请求状态的污染
export default function createApp(_url) {
  // 扔出去
  return new Promise(async (resolve, reject) => {
    const app = createSSRApp(App);

    // 引入store
    const store = createPinia();
    app.use(store);

    // 引入router,根据url变化得到对应路由静态的返回
    const router = createRouter(createMemoryHistory());
    app.use(router);
    await router.push(_url || "/");
    await router.isReady();

    resolve(app);
  });
}
